package com.infonautics.action;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.hibernate.Company;
import com.hibernate.Taxprocess;
import com.hibernate.Userinfo;
import com.infonautics.dao.ITaxprocessDao;
import com.infonautics.dao.imp.ICompanyDaoImp;
import com.infonautics.dao.imp.ITaxprocessDaoImp;
import com.infonautics.page.PageBean;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.system.dao.ISystemDao;

/**
 * 
 * @author 马萍
 * 报税流程控制层
 */
public class TaxprocessAction extends ActionSupport implements Preparable,SessionAware {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Map<String,Object> session;
	private String pageUrl = "/WEB-INF/tax/";
	private String successMsg;
	private String url;
	private String errormessage;
	private Userinfo userinfo;
	private ISystemDao<Taxprocess> taxprocessDao = new ITaxprocessDaoImp();
	private ITaxprocessDao taxDao = new ITaxprocessDaoImp();
	private Taxprocess tax;
	private PageBean<Taxprocess> pageBean;
	private int page = 1;
	private int id;
	private String name;
	
	
	/*
	 * 验证用户信息
	 * (non-Javadoc)
	 * @see com.opensymphony.xwork2.Preparable#prepare()
	 */
	@Override
	public void prepare() throws Exception {
		
		if(session.containsKey("userinfo")){
			
			if(session.get("userinfo")!=null){
				
				userinfo=(Userinfo)session.get("userinfo");
			}
		}
	}

	/*
	 * 跳转到添加页面
	 */
	public String addPage() throws Exception{
		
		return "input";
	}
	
	/*
	 * 添加报税流程
	 */
	public String add() throws Exception{
		
		taxprocessDao.doAdd(tax);
		doMsgHandle("添加成功","Taxprocess_list.action");
		return TaxprocessAction.SUCCESS;
	}
	
	/*
	 * 跳转到修改报税流程
	 */
	public String modifyPage() throws Exception{
		
		tax = taxprocessDao.doOne(id);
		return "input";
	}
	
	/*
	 * 修改报税流程
	 */
	public String modify() throws Exception{
		
		taxprocessDao.doModfiy(tax);
		doMsgHandle("修改成功", "Taxprocess_list.action");
		return TaxprocessAction.SUCCESS;
	}
	
	/*
	 * 删除报税流程
	 */
	public String delete() throws Exception{
		
		taxprocessDao.doDelete(id);
		doMsgHandle("删除成功", "Taxprocess_list.action");
		return TaxprocessAction.SUCCESS;
	}
	
	public String query() throws Exception{
		String queryString = "";
		if(name !=null && !name.equals("")){
			name=new String(name.getBytes("ISO8859-1"),"UTF-8");
			queryString += "and title like '%" + name + "%'";
		}
		pageBean = taxDao.doQueryList(20, page, queryString);
		pageBean.setQueryString("&title="+name);
		return "list";
	}
	
	/*
	 * 分页查询办税流程
	 */
	public String list() throws Exception{
		
		pageBean = taxDao.doTaxprocessList(20, page);
		return "input";
	}
	
	//服务方法
		private void doMsgHandle(String successMsg,String url){
			this.successMsg=successMsg;
			this.url=url;
		}
		
	public String getPageUrl() {
		return pageUrl;
	}

	public void setPageUrl(String pageUrl) {
		this.pageUrl = pageUrl;
	}

	public String getSuccessMsg() {
		return successMsg;
	}

	public void setSuccessMsg(String successMsg) {
		this.successMsg = successMsg;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getErrormessage() {
		return errormessage;
	}

	public void setErrormessage(String errormessage) {
		this.errormessage = errormessage;
	}

	public Userinfo getUserinfo() {
		return userinfo;
	}

	public void setUserinfo(Userinfo userinfo) {
		this.userinfo = userinfo;
	}

	public Taxprocess getTax() {
		return tax;
	}

	public void setTax(Taxprocess tax) {
		this.tax = tax;
	}

	public PageBean<Taxprocess> getPageBean() {
		return pageBean;
	}

	public void setPageBean(PageBean<Taxprocess> pageBean) {
		this.pageBean = pageBean;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Map<String, Object> getSession() {
		return session;
	}
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
		
	}


}
